package com.mxpio.erp.plan.service.impl;

import com.mxpio.erp.common.enums.OrderStatusEnums;
import com.mxpio.erp.common.plan.entity.OrganizationDemand;
import com.mxpio.erp.common.plan.entity.OrganizationDemandLine;
import com.mxpio.erp.common.plan.service.OrganizationDemandLineService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrganizationDemandLineServiceImpl extends BaseServiceImpl<OrganizationDemandLine> implements OrganizationDemandLineService {
    @Transactional(readOnly = false)
    @Override
    public Page<OrganizationDemandLine> listPage(Pageable page, Criteria c){
        return JpaUtil.linq(OrganizationDemandLine.class)
                .collect("bizNo", OrganizationDemand.class, "bizNo")
                .exists(OrganizationDemand.class)
                .equalProperty("bizNo", "bizNo")
                .notEqual("closeStatus", OrderStatusEnums.CloseStatus.CLOSED.getStatusCode())
                .equal("bpmnStatus", OrderStatusEnums.BpmnStatus.AUDITED.getStatusCode())
                .notEqual("orderStatus", OrderStatusEnums.OrderStatus.CLEARED.getStatusCode())
                .end()
                .where(c)
                .paging(page);
    }
    @Transactional(readOnly = false)
    @Override
    public List<OrganizationDemandLine> listAll(Criteria c){
        return JpaUtil.linq(OrganizationDemandLine.class)
                .collect("bizNo", OrganizationDemand.class, "bizNo")
                .exists(OrganizationDemand.class)
                .equalProperty("bizNo", "bizNo")
                .notEqual("closeStatus", OrderStatusEnums.CloseStatus.CLOSED.getStatusCode())
                .equal("bpmnStatus", OrderStatusEnums.BpmnStatus.AUDITED.getStatusCode())
                .notEqual("orderStatus", OrderStatusEnums.OrderStatus.CLEARED.getStatusCode())
                .end()
                .where(c).list();
    }
}
